<form action="{:sysuri()}" method="post" data-auto="true" class="layui-form layui-card"  lay-filter="form" id="form">

    <div class="layui-card-body padding-left-40">
        {foreach $config_rule as $v}

        <!--        字符-->
        {if $v['form_type'] == 'string'}
        <div class="layui-form-item">
            <label class="layui-form-label {if $v['is_required']} label-required {/if}">{$v['name']}</label>
            <div class="layui-input-block">
                <input type="text" name="{$v['code']}" placeholder="{:lang('请输入')}{$v['name']}" lay-verify="{$v['required']}" class="layui-input" value="{$config_data[$v['code']]|default=$v['default_value']}">
                <p class="help-block">{$v['desc']}</p>
            </div>
        </div>
        {/if}

        <!--        密码-->
        {if $v['form_type'] == 'password'}
        <div class="layui-form-item">
            <label class="layui-form-label {if $v['is_required']} label-required {/if}">{$v['name']}</label>
            <div class="layui-input-block">
                <input type="password" name="{$v['code']}" placeholder="{:lang('请输入')}{$v['name']}" lay-verify="{$v['required']}" class="layui-input" value="{$config_data[$v['code']]|default=$v['default_value']}">
                <p class="help-block">{$v['desc']}</p>
            </div>
        </div>
        {/if}

        <!--        数值-->
        {if $v['form_type'] == 'number'}
        <div class="layui-form-item">
            <label class="layui-form-label {if $v['is_required']} label-required {/if}">{$v['name']}</label>
            <div class="layui-input-block">
                <input type="number" name="{$v['code']}" placeholder="{:lang('请输入')}{$v['name']}" lay-verify="{$v['required']}" class="layui-input" value="{$config_data[$v['code']]|default=$v['default_value']}">
                <p class="help-block">{$v['desc']}</p>
            </div>
        </div>
        {/if}

        <!--        日期时间-->
        {if $v['form_type'] == 'datetime'}
        <div class="layui-form-item">
            <label class="layui-form-label {if $v['is_required']} label-required {/if}">{$v['name']}</label>
            <div class="layui-input-block">
                <input data-date-time name="{$v['code']}" placeholder="{:lang('请输入')}{$v['name']}" lay-verify="{$v['required']}" class="layui-input" value="{$config_data[$v['code']]|default=$v['default_value']}">
                <p class="help-block">{$v['desc']}</p>
            </div>
        </div>
        {/if}

        <!--        日期时间区间-->
        {if $v['form_type'] == 'datetimerange'}
        <div class="layui-form-item">
            <label class="layui-form-label {if $v['is_required']} label-required {/if}">{$v['name']}</label>
            <div class="layui-input-block">
                <input data-datetime-range name="{$v['code']}" placeholder="{:lang('请输入')}{$v['name']}" lay-verify="{$v['required']}" class="layui-input" value="{$config_data[$v['code']]|default=$v['default_value']}">
                <p class="help-block">{$v['desc']}</p>
            </div>
        </div>
        {/if}

        <!--        文本-->
        {if $v['form_type'] == 'txt'}
        <div class="layui-form-item">
            <label class="layui-form-label {if $v['is_required']} label-required {/if}">{$v['name']}</label>
            <div class="layui-input-block">
                <textarea name="{$v['code']}" placeholder="{:lang('请输入')}{$v['name']}" lay-verify="{$v['required']}" class="layui-textarea">{$config_data[$v['code']]|default=$v['default_value']}</textarea>
                <p class="help-block">{$v['desc']}</p>
            </div>
        </div>
        {/if}

        <!--        编辑器-->
        {if $v['form_type'] == 'editor'}
        <div class="layui-form-item">
            <label class="layui-form-label {if $v['is_required']} label-required {/if}">{$v['name']}</label>
            <div class="layui-input-block">
                <textarea name="{$v['code']}" placeholder="{:lang('请输入')}{$v['name']}" lay-verify="{$v['required']}" class="layui-textarea" style="height: 350px;">{$config_data[$v['code']]|default=$v['default_value']}</textarea>
                <p class="help-block">{$v['desc']}</p>
            </div>
        </div>
        <script>
            $(function () {
                // 异步加载富文本编辑器
                require(['ckeditor'], function () {
                    setTimeout(function () {
                        // 初始化富文本编辑器
                        window.createEditor('[name={$v["code"]}]', {height: 350});
                    },500)
                });
            });
        </script>
        {/if}

        <!--        单选-->
        {if $v['form_type'] == 'radio'}
        <div class="layui-form-item">
            <label class="layui-form-label {if $v['is_required']} label-required {/if}">{$v['name']}</label>
            <div class="layui-input-block">
                {foreach $v['parameter'] as $parameter}
                <input type="radio" name="{$v['code']}" data-name="{$v['code']}" value="{$parameter[0]}" title="{$parameter[1]}"
                       lay-verify="{if $v['is_required']}labelrequired{/if}"
                       {if isset($config_data[$v['code']]) and ($parameter[0] eq $config_data[$v['code']])} checked {/if}
                       {if !isset($config_data[$v['code']]) and ($parameter[0] eq $v['default_value'])} checked {/if}
                >
                {/foreach}
                <p class="help-block">{$v['desc']}</p>
            </div>
        </div>
        {/if}

        <!--        多选-->
        {if $v['form_type'] == 'checkbox'}
        <div class="layui-form-item">
            <label class="layui-form-label {if $v['is_required']} label-required {/if}">{$v['name']}</label>
            <div class="layui-input-block">
                {foreach $v['parameter'] as $parameter}
                <input type="checkbox" name="{$v['code']}[]" data-name="{$v['code']}" value="{$parameter[0]}" title="{$parameter[1]}" lay-skin="primary" lay-verify="{if $v['is_required']}labelrequired{/if}"
                       {if isset($config_data[$v['code']]) and in_array($parameter[0],json_decode($config_data[$v['code']],320))} checked {/if}
                       {if !isset($config_data[$v['code']]) and in_array($parameter[0],json_decode($v['default_value'],320))} checked {/if}
                >
                {/foreach}
                <p class="help-block">{$v['desc']}</p>
            </div>
        </div>
        {/if}

        <!--        下拉框-->
        {if $v['form_type'] == 'select'}
        <div class="layui-form-item">
            <label class="layui-form-label {if $v['is_required']} label-required {/if}">{$v['name']}</label>
            <div class="layui-input-block">
                <select name="{$v['code']}" lay-verify="{$v['required']}" lay-search>
                    <option value="">{:lang('请选择')}</option>
                    {foreach $v['parameter'] as $parameter}
                    <option value="{$parameter[0]}"
                            {if isset($config_data[$v['code']]) and ($parameter[0] eq $config_data[$v['code']])} selected {/if}
                            {if !isset($config_data[$v['code']]) and ($parameter[0] eq $v['default_value'])} selected {/if}
                    >{$parameter[1]}</option>
                    {/foreach}
                </select>
                <p class="help-block">{$v['desc']}</p>
            </div>
        </div>
        {/if}

        <!--        文件-->
        {if $v['form_type'] == 'file'}
        <div class="layui-form-item">
            <label class="layui-form-label {if $v['is_required']} label-required {/if}">{$v['name']}</label>
            <div class="layui-input-block">
                <div style="display: flex;">
                    <a data-file data-field="{$v['code']}" class="layui-btn layui-bg-blue">{:lang('上传文件')}</a>
                    <input type="text" name="{$v['code']}" lay-verify="{$v['required']}" readonly class="layui-input" value="{$config_data[$v['code']]|default=$v['default_value']}">
                </div>
                <p class="help-block">{$v['desc']}</p>
            </div>
        </div>
        {/if}

        <!--        单图-->
        {if $v['form_type'] == 'pic'}
        <div class="layui-form-item">
            <label class="layui-form-label {if $v['is_required']} label-required {/if}">{$v['name']}</label>
            <div class="layui-input-block">
                <div class="help-images">
                    <input name="{$v['code']}" data-max-width="500" data-max-height="500" type="hidden" lay-verify="{$v['required']}" value="{$config_data[$v['code']]|default=$v['default_value']}">
                    <script>$('[name=' + '{$v["code"]}' + ']').uploadOneImage();</script>
                </div>
                <p class="help-block">{$v['desc']}</p>
            </div>
        </div>
        {/if}

        <!--        多图-->
        {if $v['form_type'] == 'pics'}
        <div class="layui-form-item">
            <label class="layui-form-label {if $v['is_required']} label-required {/if}">{$v['name']}</label>
            <div class="layui-input-block">
                <div class="help-images">
                    <input name="{$v['code']}" data-max-width="2048" data-max-height="1024" type="hidden" lay-verify="{$v['required']}" value="{$config_data[$v['code']]|default=$v['default_value']}">
                    <script>$('[name=' + '{$v["code"]}' + ']').uploadMultipleImage();</script>
                </div>
                <p class="help-block">{$v['desc']}</p>
            </div>
        </div>
        {/if}

        {/foreach}

    </div>

    <div class="hr-line-dashed"></div>
    {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}

    <div class="layui-form-item text-center">
        <button class="layui-btn" type='button' lay-submit lay-filter="saveBtn" id="saveBtn">{:lang('保存数据')}</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="{:lang('确定要取消编辑吗？')}" data-close>{:lang('取消编辑')}</button>
    </div>

</form>
{block name='script'}
<script>
    $(function () {

        //监听提交
        layui.form.on('submit(saveBtn)', function (data) {
            // console.log(data.field);return ;
            $.ajax({
                url: "{:url()}",
                cache: false,
                // processData: false, // 不处理数据
                // contentType: false, // 不设置内容类型
                type: 'POST',
                dataType: 'json',
                data: data.field,
                beforeSend: (res)=>{
                    indexload = layer.load(3, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                },
                complete: (res)=>{
                    layer.close(indexload);
                },
                success: function(data){
                    // console.log(data);
                    if(data.code == 1){
                        layer.msg(data.info, {icon: 1,time: 1000},function(){
                            layer.close($('#saveBtn').parents('div.layui-layer-page').attr('times'));
                        })
                    }else{
                        layer.msg(data.info);
                    }
                },
                error: function(err){
                    // console.log(err);
                    layer.msg(err.status+err.statusText);
                }
            })

            return false;
        });

    });
</script>
{/block}